﻿using System;
using System.Dynamic;
using System.Collections.Generic;
using System.Web.Mvc;

using Fuse8.DomainFramework.Common;

namespace Fuse8.ContentManagementFramework.Web.MvcPowered
{
    public static class ExpandoObjectExtensions
    {
        public static ExpandoObject ToExpando(this object anonymousObject)
        {
            IDictionary<string, object> result = new ExpandoObject();

            if (anonymousObject != null)
            {
                IDictionary<string, object> anonymousDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(anonymousObject);

                foreach (var item in anonymousDictionary)
                {
                    result.Add(item);
                }
            }

            return result as ExpandoObject;
        }
    }
}
